import { requestClient } from '#/api/request';

// 房间接口定义
export interface Room {
  id: string;
  number: string;
  type: string;
  status: string;
  capacity: number;
  occupied: number;
  openTime?: string;
  handCard?: string;
  notes?: string;
  icon?: string;
}

// 房间状态类型
export type RoomStatus =
  | 'vacant'
  | 'occupied'
  | 'disabled'
  | 'dirty'
  | 'willDepart'
  | 'hourly'
  | 'earlyMorning';

// 房型类型
export type RoomType = 'lounge' | 'chess' | 'vip' | 'guest';

// 获取房间列表请求参数
export interface GetRoomListParams {
  roomType?: RoomType;
  status?: RoomStatus;
  roomNumber?: string;
  page?: number;
  pageSize?: number;
}

// 获取房间列表响应
export interface GetRoomListResponse {
  list: Room[];
  total: number;
  page: number;
  pageSize: number;
}

// 开房请求参数
export interface OpenRoomParams {
  roomNumber: string;
  handCard: string;
  occupants: number;
  notes?: string;
}

// 修改房态请求参数
export interface ModifyStatusParams {
  roomNumber: string;
  newStatus: RoomStatus;
  reason?: string;
}

// 退房请求参数
export interface CheckOutParams {
  roomNumber: string;
  amount: number;
  notes?: string;
}

// 换房请求参数
export interface ChangeRoomParams {
  oldRoomNumber: string;
  newRoomNumber: string;
  reason?: string;
}

// 入账请求参数
export interface AccountEntryParams {
  roomNumber: string;
  items: Array<{
    name: string;
    price: number;
    quantity: number;
  }>;
  notes?: string;
}

// 添加备注请求参数
export interface AddNotesParams {
  roomNumber: string;
  notes: string;
}

// 补卡请求参数
export interface ReplenishCardParams {
  roomNumber: string;
  newHandCard: string;
  reason: 'lost' | 'damaged' | 'other';
  notes?: string;
}

// 批量修改房态请求参数
export interface BatchModifyStatusParams {
  roomNumbers: string[];
  targetStatus: RoomStatus;
  reason?: string;
}

// 入住请求参数
export interface CheckInParams {
  roomNumber: string;
  handCard: string;
  occupants: number;
  days: number;
  guestName: string;
  phone: string;
  idCard: string;
  notes?: string;
}

// 房态统计响应
export interface RoomStatusStats {
  roomType: string;
  vacant: number;
  occupied: number;
  disabled: number;
  dirty: number;
  willDepart: number;
}

// API函数

/**
 * 获取房间列表
 */
export function getRoomList(params: GetRoomListParams) {
  return requestClient.get<GetRoomListResponse>('/spa/room/list', { params });
}

/**
 * 开房
 */
export function openRoom(data: OpenRoomParams) {
  return requestClient.post('/spa/room/open', data);
}

/**
 * 修改房态
 */
export function modifyRoomStatus(data: ModifyStatusParams) {
  return requestClient.post('/spa/room/modify-status', data);
}

/**
 * 退房
 */
export function checkOut(data: CheckOutParams) {
  return requestClient.post('/spa/room/checkout', data);
}

/**
 * 换房
 */
export function changeRoom(data: ChangeRoomParams) {
  return requestClient.post('/spa/room/change', data);
}

/**
 * 入账
 */
export function accountEntry(data: AccountEntryParams) {
  return requestClient.post('/spa/room/account-entry', data);
}

/**
 * 添加备注
 */
export function addNotes(data: AddNotesParams) {
  return requestClient.post('/spa/room/add-notes', data);
}

/**
 * 补卡
 */
export function replenishCard(data: ReplenishCardParams) {
  return requestClient.post('/spa/room/replenish-card', data);
}

/**
 * 批量修改房态
 */
export function batchModifyStatus(data: BatchModifyStatusParams) {
  return requestClient.post('/spa/room/batch-modify-status', data);
}

/**
 * 入住
 */
export function checkIn(data: CheckInParams) {
  return requestClient.post('/spa/room/checkin', data);
}

/**
 * 获取房态统计
 */
export function getRoomStatusStats() {
  return requestClient.get<RoomStatusStats[]>('/spa/room/status-stats');
}

/**
 * 搜索房间
 */
export function searchRoom(roomNumber: string) {
  return requestClient.get<Room[]>('/spa/room/search', {
    params: { roomNumber },
  });
}

/**
 * 获取可用房间列表
 */
export function getAvailableRooms(roomType?: RoomType) {
  return requestClient.get<Room[]>('/spa/room/available', {
    params: { roomType },
  });
}
